<?php

namespace app\api\model;

use think\Model;
use think\Session;

class UserSubjectModel extends Model
{

    // 表名
    protected $name = 'user_subject';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    public static function addUserSub($data){
        $newdata = [
            'user_id'=>$data['user_id'],
            'subject_id'=>$data['subject_id'],
            'order_id'=>$data['id'],
            'createtime'=>time(),
            'day'=>$data['day'],
            'card_id'=>isset($data['card_id']) ? $data['card_id'] : '',
        ];
        if($data['card_id']){
            $cardModel = new CardsModel();
            $cardModel->where(['id'=>$data['card_id']])->update(['status'=>2]);
        }
        $model = new UserSubjectModel();
        $model->save($newdata);
    }
}
